<template>
	<view class="webview-container">
		<web-view :src="webUrl" @message="handleMessage" @error="handleError"></web-view>
	</view>
</template>

<script>
export default {
	name: 'WebView',
	data() {
		return {
			webUrl: ''
		}
	},
	onLoad(options) {
		// 获取传入的URL参数
		if (options.url) {
			this.webUrl = decodeURIComponent(options.url);
		}
		
		// 设置页面标题
		if (options.title) {
			uni.setNavigationBarTitle({
				title: decodeURIComponent(options.title)
			});
		}
	},
	methods: {
		// 处理网页消息
		handleMessage(event) {
			console.log('收到网页消息:', event.detail.data);
		},
		
		// 处理加载错误
		handleError(event) {
			console.error('网页加载错误:', event);
			uni.showToast({
				title: '网页加载失败',
				icon: 'none'
			});
		}
	}
}
</script>

<style lang="scss" scoped>
.webview-container {
	width: 100%;
	height: 100vh;
}
</style>
